package com.jboost.hyk.common.entity;


import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.jboost.common.system.base.entity.JBoostEntity;

import java.util.Date;

/**
 * @Description: 机构知识
 * @Author: cxn
 * @Date:   2022-11-07
 * @Version: V1.0
 */
@Data
@TableName("hyk_business_library")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="hyk_business_library对象", description="机构知识")
public class BusinessLibrary extends JBoostEntity{

    /**businessId*/
    @ApiModelProperty(value = "businessId")
    private String businessId;

    /**购买的知识 ids*/
    @ApiModelProperty(value = "购买的知识 id")
    private String libraryId;

    /**最早一个知识的到期时间*/
    @ApiModelProperty(value = "最早一个知识的到期时间")
    private java.util.Date firstInvalidTime;

    /**最后一个知识的到期时间*/
    @ApiModelProperty(value = "最后一个知识的到期时间")
    private java.util.Date lastInvalidTime;

    /**状态：valid-正常；part_expire-部分到期；expired-已过期；*/
    @ApiModelProperty(value = "状态：valid-正常；part_expire-部分到期；expired-已过期；")
    private String status;

    /**包含的知识点数量*/
    @ApiModelProperty(value = "包含的知识点数量")
    private Integer pointCount;

    @ApiModelProperty(value = "知识在机构内被使用次数")
    private Integer useNum;

    @ApiModelProperty(value = "机构购买知识的快照id")
    private String librarySnapshotId;

    public String generateStatus() {
        if (null == firstInvalidTime){
            this.status = "valid";
            return this.status;
        }
        if (null == lastInvalidTime){
            this.status = "valid";
            return this.status;
        }
        if (new Date().getTime() > this.lastInvalidTime.getTime()){
            this.status = "expired";
        }else if (new Date().getTime() > this.firstInvalidTime.getTime()){
            this.status = "part_expire";
        }else {
            this.status = "valid";
        }
        return this.status;
    }
}
